from langchain_core.documents import Document
import typing as T
from pathlib import Path
from io import BytesIO
from .iload import DocumentLoaderFactory
from .ispiliter import DocumentSpliterFactory


def loader_spliter(
    blob: T.Union[str, Path, bytes, BytesIO],
    uuid: str,
    file_name: str,
    file_type: str,
    chunk_size: int = 256,
    chunk_overlap: int = 128,
    **kwargs,
) -> T.List[Document]:
    loder = DocumentLoaderFactory.get_loader(file_type)
    documents = loder.load(blob, uuid, file_name, **kwargs)
    spliter = DocumentSpliterFactory.get_spliter(file_type)
    documents = spliter.spliter(documents, chunk_size, chunk_overlap)
    return documents
